package leetcodecompetition.D361;

import java.util.stream.Stream;

/**
 * @Author: Siantar
 * @Date: 2023-09-03-10:46
 * @Description: 1.0
 */
public class T8040 {
    public int minimumOperations(String num) {
        int res = 0;
        for (char c : num.toCharArray()) {
            if (c == '0') res++;
        }
        res = Math.min(res, f(num, '0', '0'));
        res = Math.min(res, f(num, '5', '2'));
        res = Math.min(res, f(num, '0', '5'));
        res = Math.min(res, f(num, '5', '7'));
        return res;
    }

    public int f(String num, char num1, char num2) {
        boolean b = false;
        int res = 0;
        for (int i = num.length() - 1; i >= 0; i--) {
            char c = num.charAt(i);
            res++;
            if (!b && c == num1) {
                b = true;
                res--;
                System.out.println(num1 + " " + num2 + " " + i);
                continue;
            }
            if (b && c == num2) {
                res--;
                System.out.println(" " + num1 + " " + num2 + " " + i);
                return res;
            }

        }
        return num.length();
    }
}
